"""统计目录大小"""
import os

def st(target_dir):

    sum_file = 0
    dlist = os.listdir(target_dir)

    for x in dlist:
        # 添加目录
        file1 = os.path.join(target_dir, x)
        if os.path.isfile(file1):
            sum_file += os.stat(file1).st_size  # 是文件就统计大小
        if os.path.isdir(file1):
            sum_file +=st(file1)  # 是目录就递归函数

    return sum_file

def run_start():
    file_name = input("请输入在当前目录下需要统计文件夹大小的文件夹名称：")
    file_name = "./" + file_name
    return file_name
def run_choice():
    print("========继续请输入1========")
    print("========退出请输入2========")
    flag = input("请输入:")
    return flag
def run():

    while True:
        file_name = run_start()
        if os.path.exists(file_name):
            print(st(file_name))
            while True:
                flag = run_choice()
                if flag == "1":
                    break
                elif flag == "2":
                    print("=" * 12, "再见", "=" * 14)
                    return
                else:
                    print("========无效指令========")
        else:
            print("=======文件夹名称错误或者文件夹不存在=======")
            while True:
                flag1 =run_choice()
                if flag1 == "1":
                    break
                elif flag1 == "2":
                    print("=" * 12, "再见", "=" * 14)
                    return
                else:
                    print("========无效指令========")
if __name__ == '__main__':
    run()